package com.guochenglang.www.util;

import com.guochenglang.www.common.DefineCode;

import java.util.Random;

/**
 * 生成验证码
 *
 * @author 郭程朗
 */
public class CreateCode {
    /**
     * 生成验证码
     *
     * @return 验证码
     */
    public static String createCode() {
        Random random = new Random();
        StringBuffer code = new StringBuffer(DefineCode.CODE_LENGTH);
        //生成预定长度的四个字母
        for (int i = 0; i < DefineCode.CODE_LENGTH; i++) {
            int index = random.nextInt(DefineCode.CHARACTERS.length());
            code.append(DefineCode.CHARACTERS.charAt(index));
        }
        return String.valueOf(code);
    }
}
